package com.jy.readers.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jy.common.annotation.Log;
import com.jy.common.core.controller.BaseController;
import com.jy.common.core.domain.AjaxResult;
import com.jy.common.enums.BusinessType;
import com.jy.readers.domain.Readers;
import com.jy.readers.service.IReadersService;
import com.jy.common.utils.poi.ExcelUtil;
import com.jy.common.core.page.TableDataInfo;

/**
 * 图书馆用户信息Controller
 * 
 * @author ruoyi
 * @date 2025-05-30
 */
@RestController
@RequestMapping("/readers/readers")
public class ReadersController extends BaseController
{
    @Autowired
    private IReadersService readersService;

    /**
     * 查询图书馆用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('readers:readers:list')")
    @GetMapping("/list")
    public TableDataInfo list(Readers readers)
    {
        startPage();
        List<Readers> list = readersService.selectReadersList(readers);
        return getDataTable(list);
    }

    /**
     * 导出图书馆用户信息列表
     */
    @PreAuthorize("@ss.hasPermi('readers:readers:export')")
    @Log(title = "图书馆用户信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Readers readers)
    {
        List<Readers> list = readersService.selectReadersList(readers);
        ExcelUtil<Readers> util = new ExcelUtil<Readers>(Readers.class);
        util.exportExcel(response, list, "图书馆用户信息数据");
    }

    /**
     * 获取图书馆用户信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('readers:readers:query')")
    @GetMapping(value = "/{userId}")
    public AjaxResult getInfo(@PathVariable("userId") Long userId)
    {
        return success(readersService.selectReadersByUserId(userId));
    }

    /**
     * 新增图书馆用户信息
     */
    @PreAuthorize("@ss.hasPermi('readers:readers:add')")
    @Log(title = "图书馆用户信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Readers readers)
    {
        return toAjax(readersService.insertReaders(readers));
    }

    /**
     * 修改图书馆用户信息
     */
    @PreAuthorize("@ss.hasPermi('readers:readers:edit')")
    @Log(title = "图书馆用户信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Readers readers)
    {
        return toAjax(readersService.updateReaders(readers));
    }

    /**
     * 删除图书馆用户信息
     */
    @PreAuthorize("@ss.hasPermi('readers:readers:remove')")
    @Log(title = "图书馆用户信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userIds}")
    public AjaxResult remove(@PathVariable Long[] userIds)
    {
        return toAjax(readersService.deleteReadersByUserIds(userIds));
    }
}
